package com.etb.wisdom.eframe.auth.action;

import java.io.IOException;

import javax.servlet.ServletException;

import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

import com.etb.core.exception.AuthException;
import com.etb.web.action.ETBAction;
import com.etb.web.eui.utils.EuiUtil;
import com.etb.web.vo.Party;
import com.etb.wisdom.eframe.auth.service.AuthService;

@Action("auth")
public class AuthAction extends ETBAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7705107130146086665L;

	@Autowired
	private AuthService authService;
	
	public void getMenuData() {
		Party party = (Party)session.getAttribute("party");
		EuiUtil.toJson(authService.getMenuData(party.getRoleIds().toArray()));
	}
	
	public void initParty() {
		authService.initParty(request);
		try {
			request.getRequestDispatcher(request.getAttribute("destination").toString()).forward(request, response);
		} catch (ServletException | IOException e) {
			throw new AuthException(e);
		}
	}

}
